import { Role } from '@app/modules';
import { AuditBase } from '@app/types/entities';
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm';

import { Profile } from './profile.entity';

@Entity()
export class Account extends AuditBase {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ length: 20, unique: true })
  username: string;

  @Column({ length: 20 })
  password: string;

  @OneToOne(() => Profile, (profile) => profile.account, { cascade: true })
  @JoinColumn()
  profile: Profile;

  @ManyToMany(() => Role, (role) => role.accounts, { cascade: true })
  @JoinTable()
  roles: Role[];
}
